﻿@model ListViewModel<CommonSearchValues2, IQueryable<Recuper>>
@{ var tm = new WebUI.Models.aspnet_Users();}
@{ var tm2 = new WebUI.Models.Recuper();}
@*@Html.Partial("SearchPartial", new ViewDataDictionary
{ 
    { "SearchAction", "RecuperList" },
    { "UpdateTargetId", "ListView" },
    {"NewLinkTitle", "新建患者注册"},
    {"NewLinkAction", "RecuperEdit"},
    {"NewLinkArg", new { ID = Guid.Empty }},    
    {"DialogTitle", "患者注册"}
})*@
@{
    ViewBag.Title = "住院管理";
}
<div class="toolbox">
    @if (SiteUser.IsDoctorDepManager)
    {
        <div class="icons icons-add ">
            患者住院登记 &nbsp; &nbsp;
            @Ajax.ActionLink("[录入]", "QueryRecUser", new { UserID = Guid.Empty }, new AjaxOptions() { LoadingElementId = "OnLoadingSpan", UpdateTargetId = "dialogbox", OnComplete = "showDialog('患者注册');", HttpMethod = "Get", InsertionMode = InsertionMode.Replace, OnFailure = "OnSiteError" })
            &nbsp; &nbsp; <a href="javascript:void(0)" onclick="$('#searchpan').toggle('fast');">[切换高级查询...]</a>
        </div>
    }
    else
    {
        <div class="catalog-title">
            患者住院登记 &nbsp; &nbsp; <a href="javascript:void(0)" onclick="$('#searchpan').toggle('blind');">[查询]</a>
        </div>
    }

        @using (Ajax.BeginForm("RecuperList", new { IsView = false }, new AjaxOptions { HttpMethod = "Post", LoadingElementId = "OnLoadingSpan", UpdateTargetId = "main", OnFailure = "OnSiteError" }))
        {
            <div class="small-input">
                @Html.HiddenFor(m => Model.PageSize)
                <input type="hidden" name="PageIdx" id="qspidx" value="0" />
                <table class="width noborder inlinelabels-5" style="background-color: #f8f8f8">
                    <tr>
                        <td valign="top">
                            <label>姓名：</label>@Html.EditorFor(m => m.SearchFrom.V1)
                            <br />
                            <label>出院：</label>@Html.DropDownListFor(m => m.SearchFrom.V11, new SelectList("已出院,未出院".Split(','), Model.SearchFrom.V11), "", null)
                        </td>
                        <td><label>性别：</label>@Html.DropDownListFor(m => m.SearchFrom.V2, new SelectList("男,女".Split(','), Model.SearchFrom.V2), "", null)
                            <br />
                            <label>随访发起：</label>@Html.DropDownListFor(m => m.SearchTo.V10, new SelectList("可发起随访,不发起随访".Split(','), Model.SearchTo.V10), "", null)
                        </td>
                        <td><label>手机号码：</label>@Html.EditorFor(m => m.SearchFrom.V4)
                            <label>主管医生：</label>@Html.DropDownListFor(m => m.SearchFrom.V6, new SelectList(ViewBag.Users, "UserID", "UserName", Model.SearchFrom.V6), "全部")
                            <label>随访状况：</label>@Html.DropDownListFor(m => m.SearchFrom.V12, new SelectList("已参与,未参与".Split(','), Model.SearchFrom.V12), "全部", null)                            
                            <br />
                            <label>随访类型：</label>@Html.EditorFor(m => m.SearchTo.V6)                        
                        </td>
                        <td valign="top">&nbsp;&nbsp;&nbsp; @Helpers.SubmitButton("查询", "qssubmit")
                        </td>
                    </tr>                                        
                </table>
                <table id="searchpan" class="width noborder inlinelabels-5" style="background-color: #f8f8f8;display: none;">
                    <tr>
                        <td valign="top">
                            <span class="big-input">
                                <label>出院诊断：</label>
                                @Html.EditorFor(m => m.SearchFrom.V8)<br />
                                <label>手术名称：</label>
                                @Html.EditorFor(m => m.SearchFrom.V10)</span>
                            <br />
                            <label>病案号：</label>@Html.EditorFor(m => m.SearchFrom.V3)至 @Html.EditorFor(m => m.SearchTo.V3)
                        </td>
                        <td align="left" valign="top">
                            <label>出生日期：</label>
                            @Html.EditorFor(m => m.SearchFrom.V5, "DateTimeStr")至 @Html.EditorFor(m => m.SearchTo.V5, "DateTimeStr")<br />
                            <label>入院时间：</label>
                            @Html.EditorFor(m => m.SearchFrom.V7, "DateTimeStr")至 @Html.EditorFor(m => m.SearchTo.V7, "DateTimeStr")<br />
                            <label>出院时间：</label>
                            @Html.EditorFor(m => m.SearchFrom.V9, "DateTimeStr")至 @Html.EditorFor(m => m.SearchTo.V9, "DateTimeStr")
                        </td>
                    </tr>
                </table>
            <div class="inlinelabels-5"><label>排序：</label>
            @{
            //诡异debug，html.textboxfor( model.sortorder或m.sortorder怎么也不对，但dispfor 或直接显示m.sortorder 就是对的
            //弄个变量试试也不行            //还是不行貌似html.textbox之类的有问题，靠用input就好了
            } 
                <input type="hidden" value="@Model.SortOrder" name="SortOrder" id="SortOrder" />
            @*@Html.Hidden("SortOrder",  Model.SortOrder)*@
            @Html.EditorFor(m => m.SortBy, "SelButtonsField", new { Selects = new SelectList("出院时间,姓名,年龄".Split(','), Model.SortBy) })
            </div>            </div>

        }

</div>

<table class="width">
    <tr>
        <th>
            @Html.LabelFor(model => tm.UserName)
        </th>
        <th>
            @Html.LabelFor(model => tm.Gender)
        </th>
        <th>
            @Html.Label("主管医生")
        </th>
        <th>
            @Html.Label("随访类型")
        </th>
        <th>@Html.Label("参与随访")
        </th>
        <th>
            @Html.Label("填报次数")
        </th>
        <th>
            @Html.LabelFor(model => tm2.BingAnHao)
        </th>
        <th>
            @Html.LabelFor(model => tm.MobileAlias)
        </th>
        <th>
            @Html.LabelFor(model => tm2.EnHospDay)
        </th>
        <th>
            @Html.LabelFor(model => tm2.DeHospDay)
        </th>
        <th></th>
    </tr>
    @{int dColor = 0;}
    @foreach (var item in Model.Data)
    {
        <tr class="tr-backColor@(dColor++ % 2)">
            <td>
                @Html.DisplayFor(model => item.User.UserName)
            </td>
            <td>
                @Html.DisplayFor(model => item.User.Gender)
            </td>
            <td>
                @Html.DisplayFor(model => item.Doctor.UserName)
            </td>
            <td title="@item.SuiFangLeiXing">
                @Html.FixStrSuffix(item.SuiFangLeiXing, 16)
            </td>
            @{
        var suifangcounts = item.QizSubjectObjForDoctors.Select(v => v.QizSubject.Title).ToArray();
        var suifangcounttitles = (suifangcounts.Length > 0 ? string.Join(",", suifangcounts) : "");
            }
            <td title="@(suifangcounttitles)" >
                @if (suifangcounts.Length > 0)
                {
                    @suifangcounts.Length
                }
            </td>
            <td>
                @{
                var times = item.QizSessions.Where(s => s.QizSubject.SubjectType == "常规随访单").Count() + item.QizSmsSessions.Count(v => v.SessionStatus == 3);
                }
                @Html.DisplayFor(model => times)
            </td>
            <td>
                @Html.DisplayFor(model => item.BingAnHao)
            </td>
            <td>
                @Html.DisplayFor(model => item.User.MobileAlias)
            </td>
            <td>
                @Html.DisplayFor(model => item.EnHospDay)
            </td>
            <td>
                @if (item.DeHospDay != DateTime.MinValue)
                {
                    @Html.DisplayFor(model => item.DeHospDay)
                }
            </td>
            <td>
                @Ajax.ActionLink("修改", "RecuperEnHospEdit", new { ID = item.RecuperID, _t = DateTime.Now.Ticks }, new AjaxOptions() { LoadingElementId = "OnLoadingSpan", UpdateTargetId = "dialogbox", OnComplete = "displayEnHospitalWindow();", HttpMethod = "Get", InsertionMode = InsertionMode.Replace, OnFailure = "OnSiteError" })
                @if (item.QizSubjectObjForDoctors.Count > 0 || item.QizSessions.Count > 0 || item.QizSmsSessions.Count > 0)
                {
                    <span title="已经有过于其关联的信息，如随访、填报等，无法直接删除。">删除</span>
                }
                else
                {
                    @Ajax.ActionLink("删除", "RecuperDelete", new { ID = item.RecuperID, _t = DateTime.Now.Ticks }, new AjaxOptions() { LoadingElementId = "OnLoadingSpan", UpdateTargetId = "ListView", HttpMethod = "Get", InsertionMode = InsertionMode.Replace, OnFailure = "OnSiteError", Confirm = OnConfirmDel() })
                }
                @Ajax.ActionLink("补录", "BLStartView", new { RecuperID = item.RecuperID }, new AjaxOptions() { LoadingElementId = "OnLoadingSpan", UpdateTargetId = "dialogbox", OnComplete = "displayEnHospitalWindow();", HttpMethod = "Get", InsertionMode = InsertionMode.Replace, OnFailure = "OnSiteError" })
            </td>
        </tr>
    }
</table>
<table class="width noborder">
    <tr>
        <td>
            @Html.Partial("Pagger", new PaggerViewModel { Act = "RecuperList", PageIdx = Model.PageIdx, PageCount = Model.PageCount, ItemCount = Model.ItemCount })
        </td>
        <td align="right">
            @using (Html.BeginForm("RecuperListExport", null, new { }, FormMethod.Post, new { target = "_blank", onsubmit = "alert('根据导出数据的多少，可能会有需要很长时间，导出过程请耐心等待...。');" }))
            {
                var currentFilter = new ListViewModel<CommonSearchValues, string>() { SearchFrom = Model.SearchFrom, SearchTo = Model.SearchTo };
                <span style="display: none;">
                    @Html.Hidden("CurrentFilterOfJson", System.Web.Helpers.Json.Encode(currentFilter))
                    <input type="submit" name="ExportType" value="exportdetail" id="exportdetail" />
                </span>
                <a href="#RecuperListExport" onclick="$('#exportdetail').click()">导出患者住院记录</a> 
            }
        </td>
    </tr>
</table>
@Html.Partial("TrHilighter")
@{
    var sflxs = "'" + string.Join("','", SiteUser.Department.DepartmentProfiles.Where(v => v.SettingKey.Equals("SuiFangLeiXing", StringComparison.OrdinalIgnoreCase)).Select(v => v.SettingValue).Distinct().ToArray()) + "'";    
}
<script type="text/javascript">
    function displayEnHospitalWindow() {
        showDialog('患者信息');
    };
    function displayAdvancedSearch(el) {
        if ($(el).text() != '收起') {
            $(el).text('收起');
            $('#advanced').slideDown();
        } else {
            $(el).text('高级选项');
            $('#advanced').slideUp();
        }
        return false;
    };
    $(function () {
        $("#SearchTo_V6").select2({ maximumSelectionSize: 1, tags: [ @Html.Raw(sflxs)] });
    });
</script>
<style type="text/css">
    #btn_advanced
    {
        font-size: 12px;
        padding: 3px;
        color: blue;
        text-decoration: underline;
    }

        #btn_advanced:hover
        {
            background: none;
            text-decoration: none;
        }
</style>
